package com.hb.trade.server.project.opening.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.parent.PageResult;
import com.hb.core.pojo.project.opening.dto.OpeningSetDTO;
import com.hb.core.pojo.project.opening.entity.OpeningSet;
import com.hb.core.pojo.project.opening.mapper.OpeningSetMapper;
import com.hb.core.pojo.project.section.entity.BidSection;
import com.hb.trade.server.project.opening.service.OpeningSetService;
import com.hb.trade.server.project.section.service.raw.BidSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 标段开启设置表 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2021-11-16
 */
@Service
public class OpeningSetServiceImpl extends ServiceImpl<OpeningSetMapper, OpeningSet> implements OpeningSetService {

    @Autowired
    private BidSectionService bidSectionService;

    @Override
    public PageResult<OpeningSetDTO> pageOpeningSet(OpeningSetDTO openingSet) {
        Page<OpeningSetDTO> page = baseMapper.listOpeningSetByProjectId(openingSet.pages(), openingSet);
        //处理对应标段列表
        for (OpeningSetDTO openingSetDTO : page.getRecords()) {
            List<BidSection> bidSectionList = bidSectionService.list(new LambdaQueryWrapper<BidSection>()
                    .eq(BidSection :: getOpeningSetId, openingSetDTO.getId()));
            openingSetDTO.setBidSectionList(bidSectionList);
        }
        return PageResult.get(page);
    }

    @Override
    public PageResult<BidSection> getSectionNotSelected(OpeningSetDTO openingSet) {
        Page<BidSection> page = baseMapper.getSectionNotSelected(openingSet.pages(), openingSet);
        return PageResult.get(page);
    }
}
